buttonalarm 2.2.0
Loading...
Searching...
No Matches
buttonalarm


Button ALARM Click

Button ALARM Click demo application is developed using the NECTO Studio, ensuring compatibility with mikroSDK's open-source libraries and tools. Designed for plug-and-play implementation and testing, the demo is fully compatible with all development, starter, and mikromedia boards featuring a mikroBUS™ socket.


Click Library

  • Author : Nikola Peric
  • Date : Feb 2022.
  • Type : GPIO type

Software Support

Example Description

This example showcases how to initialize and use the whole family of Button Clicks. One library is used for every single one of them. They are simple touch detectors that send a pressed/released signal and receive a PWM output which controls the backlight on the button.

Example Libraries

  • MikroSDK.Board
  • MikroSDK.Log
  • Click.ButtonAlarm

Example Key Functions

Application Init

This function initializes and configures the logger and Click modules.

void application_init ( void )
{
log_cfg_t log_cfg;
buttonalarm_cfg_t buttonalarm_cfg;
LOG_MAP_USB_UART( log_cfg );
log_init( &logger, &log_cfg );
log_info( &logger, " Application Init " );
// Click initialization.
buttonalarm_cfg_setup( &buttonalarm_cfg );
BUTTONALARM_MAP_MIKROBUS( buttonalarm_cfg, MIKROBUS_1 );
err_t init_flag = buttonalarm_init( &buttonalarm, &buttonalarm_cfg );
if ( PWM_ERROR == init_flag )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
Delay_ms ( 500 );
buttonalarm_set_duty_cycle ( &buttonalarm, 0.1 );
buttonalarm_pwm_start( &buttonalarm );
log_info( &logger, " Application Task " );
}
#define BUTTONALARM_MAP_MIKROBUS(cfg, mikrobus)
MikroBUS pin mapping.
Definition buttonalarm.h:91
err_t buttonalarm_set_duty_cycle(buttonalarm_t *ctx, float duty_cycle)
Button Alarm sets PWM duty cycle.
void application_init(void)
Definition main.c:30

Application Task

This example first increases the backlight on the button and then decreases the intensity of the backlight. When the button is touched,
reports the event in the console using UART communication.

void application_task ( void )
{
static float duty_cycle;
static uint8_t button_state;
static uint8_t button_state_old;
button_state = buttonalarm_get_button_state( &buttonalarm );
if ( button_state && ( button_state != button_state_old ) )
{
log_printf( &logger, " <-- Button pressed --> \r\n" );
for ( uint8_t n_cnt = 1; n_cnt <= 100; n_cnt++ )
{
duty_cycle = ( float ) n_cnt ;
duty_cycle /= 100;
buttonalarm_set_duty_cycle( &buttonalarm, duty_cycle );
Delay_ms ( 10 );
}
button_state_old = button_state;
}
else if ( !button_state && ( button_state != button_state_old ) )
{
for ( uint8_t n_cnt = 100; n_cnt > 0; n_cnt-- )
{
duty_cycle = ( float ) n_cnt ;
duty_cycle /= 100;
buttonalarm_set_duty_cycle( &buttonalarm, duty_cycle );
Delay_ms ( 10 );
}
button_state_old = button_state;
}
}
void application_task(void)
Definition main.c:68

Application Output

This Click board can be interfaced and monitored in two ways:

  • Application Output - Use the "Application Output" window in Debug mode for real-time data monitoring. Set it up properly by following this tutorial.
  • UART Terminal - Monitor data via the UART Terminal using a USB to UART converter. For detailed instructions, check out this tutorial.

Additional Notes and Information

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.